package com.juyu.miliao.scheduler.dao.mysql;

import com.juyu.miliao.common.dataSource.tool.distributeOperate.DistributeOperate;
import com.juyu.miliao.common.dataSource.tool.operate.Operate;
import com.juyu.miliao.scheduler.domin.User;
import com.juyu.miliao.scheduler.domin.UserWallet;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class UserInfoDao {
	@Autowired
	private SqlSession sqlSession;

	@DistributeOperate(ds = "miliao-user")
	public Long getUserInfoCount() {
		return sqlSession.selectOne("getUserInfoCount");
	}
	@DistributeOperate(ds = "miliao-user")
	public List<User> getUserListByUpdateIcon(int startNum, int pageSize){
		Map<String, Object> params = new HashMap<>();
		params.put("startNum", startNum);
		params.put("pageSize", pageSize);
		return sqlSession.selectList("getUserListByUpdateIcon", params);
	}
	
	@Operate("strategy('byUserId', #userId)")
	public int updateUserIsVip(int isVip, long userId){
		Map<String, Object> params = new HashMap<>();
		params.put("isVip", isVip);
		params.put("userId", userId);
		return sqlSession.update("updateUserIsVip", params);
	}
	
	//最热 boy 1 girl 2
	@DistributeOperate(ds = "miliao-user")
	public List<User> getHotSortUserList(int sex) {
		return sqlSession.selectList("getHotSortUserList",sex);
	}

	//最新 boy
	@DistributeOperate(ds = "miliao-user")
	public List<User> getNewSortUserList(int sex) {
		Map<String, Object> params = new HashMap<>();
		LocalDate date = LocalDate.now().minus(1, ChronoUnit.MONTHS);
		String dates =  date.toString();
		params.put("dates", dates);
		params.put("sex", sex);
		return sqlSession.selectList("getNewSortUserList", params);
	}
	
	@DistributeOperate(ds = "miliao-user")
	public List<User> getUserListRand(int randNum,List<Integer> userIds) {
		Map<String, Object> params = new HashMap<>();
		params.put("list", userIds);
		params.put("randNum", randNum);
		return sqlSession.selectList("getUserListRand",params);
	}
	//查询500个非主播用户，根据v值排序
//	@DistributeOperate(ds = "miliao-user")
//	public List<User> getCommonSortUserList() {
//		return sqlSession.selectList("getCommonSortUserList");
//	}
	@Operate("strategy('byUserId', #userId)")
	public User findUserById(long userId) {
		return sqlSession.selectOne("findUserById",userId);
	}
	//查询发现列表-优质主播
	@DistributeOperate(ds = "miliao-user")
	public List<User> getQualityHostList(List<Integer> userIds) {
		Map<String, Object> params = new HashMap<>();
		params.put("list", userIds);
		return sqlSession.selectList("getQualityHostList",params);
	}

	/**
	 * 查询颜值主播
	 */
	@DistributeOperate(ds = "miliao-user")
	public List<User> getBeautyHostList(List<Long> userIds) {
		Map<String, Object> params = new HashMap<>();
		params.put("list", userIds);
		return sqlSession.selectList("getBeautyHostList",params);
	}



	//查询发现列表-最新主播
	@DistributeOperate(ds = "miliao-user")
	public List<User> getNewQualityHostList(List<Integer> userIds) {
		Map<String, Object> params = new HashMap<>();
		params.put("list", userIds);
		return sqlSession.selectList("getNewQualityHostList",params);
	}
	//查询发现列表-最新主播
	@DistributeOperate(ds = "miliao-user")
	public List<User> getManHostList(List<Integer> userIds) {
		Map<String, Object> params = new HashMap<>();
		params.put("list", userIds);
		return sqlSession.selectList("getManHostList",params);
	}

    /**
     * 查询用户在线设置
     *
     * @param userId userId
     * @return user
     */
    @Operate("strategy('byUserId', #userId)")
    public User getUserLineStatus(Long userId) {
        return sqlSession.selectOne("getUserLineStatus", userId);
    }


	@Operate("strategy('byUserId', #id)")
	public UserWallet getUserWalletById(long id){
		return sqlSession.selectOne("getUserWalletById", id);
	}

	@DistributeOperate(ds = "miliao-user")
	public List<User> getUserListNotByUserIdList(int randNum,List<Long> userIds) {
		Map<String, Object> params = new HashMap<>();
		params.put("list", userIds);
		params.put("randNum", randNum);
		return sqlSession.selectList("getUserListNotByUserIdList",params);
	}
	@DistributeOperate(ds = "miliao-user")
	public List<User> getUserListByUserIdList(List<Integer> userIds) {
		Map<String, Object> params = new HashMap<>();
		params.put("list", userIds);
		return sqlSession.selectList("getUserListByUserIdList",params);
	}

//	@DistributeOperate(ds = "miliao-user")
//	public List<User> getOnLineGirlUsersList() {
//		return sqlSession.selectList("getOnLineGirlUsersList");
//	}
//	@DistributeOperate(ds = "miliao-user")
//	public List<User> getOnLineBoyUsersList() {
//
//    	return sqlSession.selectList("getOnLineBoyUsersList");
//	}
	@DistributeOperate(ds = "miliao-user")
	public List<User> getOnLineBoyUsersList(List<Long> range) {
		Map<String, Object> params = new HashMap<>();
		params.put("list",range);
		return sqlSession.selectList("getOnLineBoyUsersList",params);
	}
	@DistributeOperate(ds = "miliao-user")
	public List<User> getOnLineGirlUsersList(List<Long> range) {
		Map<String, Object> params = new HashMap<>();
		params.put("list",range);
		return sqlSession.selectList("getOnLineGirlUsersList",params);
	}

	//查询发现列表-置顶优质主播
	@DistributeOperate(ds = "miliao-user")
	public List<User> getQualityHostListInUserIds(List<Integer> userIds) {
		Map<String, Object> params = new HashMap<>();
		params.put("list", userIds);
		return sqlSession.selectList("getQualityHostListInUserIds",params);
	}
	//查询发现列表-置顶优质主播
	@DistributeOperate(ds = "miliao-user")
	public List<User> getNewQualityHostListInUserIds(List<Integer> userIds) {
		Map<String, Object> params = new HashMap<>();
		params.put("list", userIds);
		return sqlSession.selectList("getNewQualityHostListInUserIds",params);
	}

	//查询发现列表-置顶优质主播
	@DistributeOperate(ds = "miliao-user")
	public List<User> getManHostListInUserIds(List<Integer> userIds) {
		Map<String, Object> params = new HashMap<>();
		params.put("list", userIds);
		return sqlSession.selectList("getManHostListInUserIds",params);
	}

	@DistributeOperate(ds = "miliao-user")
    public void updateUserEnable(List<Integer> userIds) {
		Map<String, Object> params = new HashMap<>();
		params.put("userIds", userIds);
		sqlSession.update("updateUserEnable",params);
    }

	/**
	 * 修改svip状态
	 * @param userId
	 */
	@Operate("strategy('byUserId', #userId)")
	public int updateUserIsSVip(long userId) {

		return sqlSession.update("updateUserIsSVip", userId);
	}
	@Operate("strategy('byUserId', #userId)")
	public User getUserInfoByUserId(long userId) {
		return sqlSession.selectOne("getUserInfoByUserId",userId);
	}

	@DistributeOperate(ds = "miliao-user")
	public List<User> getUserHost() {
		return sqlSession.selectList("selectAllHost");
	}
	@Operate("strategy('byUserId', #userId)")
	public User selectUserById(Long userId) {
		return sqlSession.selectOne("selectUserById",userId);
	}

	/**
	 * 关闭铂金vip
	 * @param userId
	 * @return
	 */
	@Operate("strategy('byUserId', #userId)")
	public int updateUserIsPlatinumVipClose(long userId) {
		return sqlSession.update("updateUserIsPlatinumVipClose",userId);
	}

    public List<User> getHostLocationConfigByType(int listType, int locationType) {
		Map<String, Object> params = new HashMap<>();
		params.put("listType", listType);
		params.put("locationType", locationType);
		return sqlSession.selectList("getHostLocationConfigByType",params);
    }
}
